<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
if($_RQ['op']=='main'){
	$return['params']=array();
	if($_RQ['status']==1){
		$return['params']['status']=1;
	}else{
		$return['params']['status']=0;
	}
	$return['jy_giftbao']=$this->plugin_exists('jy_giftbao');
	$return['list']=array();
	$return['libao_types']=$this->libao_types;
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$return['params']=array();
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}	
	if($_RQ['status']==1){
		$return['params']['status']=1;
	}else{
		$return['params']['status']=0;
	}
	$params['status']=intval($_RQ['status']);
	$pindex = max(1, intval($_RQ['page']));
	if(intval($_RQ['num'])){
		$psize = intval($_RQ['num']);
	}else{
		$psize = 10;
	}
	$total='';
	$list=pdo_getslice('jy_weishop_sale_libao',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			if($item['type']==0){
				$item['title3']='优惠券';
				$item['title2']='赠送优惠券';
				$item['title5']='赠送优惠券';
			}elseif($item['type']==1){
				$item['title3']=$item['del_fee'];
				$item['title2']='立减'.$item['del_fee'];
				$item['title5']='立减'.$item['del_fee'];
			}elseif($item['type']==2){
				$item['title3']=$item['zhe_fee'];
				$item['title2']='打'.$item['del_fee'].'折';
				$item['title5']='打'.$item['del_fee'].'折';
			}elseif($item['type']==3){
				$item['title3']='送商品';
				$item['title2']='赠送商品';
				$item['title5']='赠送商品';
			}elseif($item['type']==4){
				$item['title3']='会员';
				$item['title2']='赠送会员';
				$item['title5']='赠送会员';
			}
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=$_RQ['id'];
	if(!$id){
		exi('请选择礼包','error');
	}	
	$item=$this->pdo_get('sale_libao',array('id'=>$id,'mid'=>$_SESSION['uid']));
	if ($item['type'] == 1) {
		$goods = $item['del_goods_ids']?json_decode($item['del_goods_ids'],true):array();
	}
	if ($item['type'] == 2) {
		$goods = $item['zhe_goods_ids']?json_decode($item['zhe_goods_ids'],true):array();
	}
	if($item['type']==0){
				$item['typetitle']='优惠券';
				$item['title3']='优惠券';
				$item['title2']='赠送优惠券';
				$item['title5']='赠送优惠券';
				$coupontitle=$this->pdo_getcolumn('coupon',array('id'=>$item['coupon_id']),'title');
				$item['desc']='使用本权益包，将直接赠送《'.$coupontitle.'》优惠券';
	}elseif($item['type']==1){
				$item['typetitle']='立减';
				$item['title3']=$item['del_fee'];
				$item['title2']='立减'.$item['del_fee'];
				$item['title5']='立减'.$item['del_fee'];
				$item['desc']='使用本权益包，购买以下商品，立减'.$item['del_fee'];
	}elseif($item['type']==2){
				$item['typetitle']='打折';
				$item['title3']=$item['zhe_fee'];
				$item['title2']='打'.$item['del_fee'].'折';
				$item['title5']='打'.$item['del_fee'].'折';
				$item['desc']='使用本权益包，购买以下商品，打'.$item['del_fee'].'折';
	}elseif($item['type']==3){
				$item['typetitle']='送商品';
				$item['title3']='送商品';
				$item['title2']='赠送商品';
				$item['title5']='赠送商品';
				$goodstitle=$this->pdo_getcolumn('goods',array('id'=>$item['goods_id']),'title');
				$item['desc']='使用本权益包，将直接赠送《'.$goodstitle.'》商品';
	}elseif($item['type']==4){
				$item['typetitle']='送会员';
				$item['title3']='会员';
				$item['title2']='赠送会员';
				$item['title5']='赠送会员';
				$leveltitle=$this->pdo_getcolumn('member_level',array('id'=>$item['member_levelid']),'title');
				$item['desc']='使用本权益包，将直接升级到'.$leveltitle;
	}
	$return['goods']=$goods;
	$return['item']=$item;
	$return['libao_types']=$this->libao_types;
	exi($return);
}
if($_RQ['op']=='open_libao'){
	$id=intval($_RQ['id']);
	$this->model('libao')->open_libao($id);
	exi('使用礼品成功!','','/sale.mylibao/');
}
?>